﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CardMonitor.Windows
{
    /// <summary>
    /// InfoWindow.xaml 的交互逻辑
    /// </summary>
    public partial class InfoWindow : Window
    {
        SynchronizationContext _syncContext = null;

        String message = null;
        int closeSeconds = 3;
        public InfoWindow()
        {
            InitializeComponent();
            message = "";
            _syncContext = SynchronizationContext.Current;

            this.Loaded += Winndow_Loaded;
        }
        public InfoWindow(String message)
        {
            InitializeComponent();
            this.message = message;
            _syncContext = SynchronizationContext.Current;

            this.Loaded += Winndow_Loaded;
        }

        private void Winndow_Loaded(object sender, RoutedEventArgs e)
        {
            txtMessage.Text = message;

            new Thread(() =>
            {
                Thread.Sleep(closeSeconds * 1000);
                _syncContext.Post(CloseWindow, "");
            }).Start();
        }
        private void CloseWindow(object text)
        {
            this.Close();
        }

        private void close(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
